package com.ruoyi.production.service.impl.seed;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.order.domain.OrderAllocation;
import com.ruoyi.order.mapper.OrderAllocationMapper;
import com.ruoyi.production.domain.seed.SeedApply;
import com.ruoyi.production.mapper.seed.SeedApplyMapper;
import com.ruoyi.production.service.seed.ISeedApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 种子申请Service业务层处理
 *
 * @author ruoyi
 * @date 2021-07-07
 */
@Service
public class SeedApplyServiceImpl implements ISeedApplyService
{
    @Autowired
    private SeedApplyMapper seedApplyMapper;
    @Autowired
    private OrderAllocationMapper orderAllocationMapper;

    /**
     * 查询种子申请
     *
     * @param seedApplyId 种子申请ID
     * @return 种子申请
     */
    @Override
    public SeedApply selectSeedApplyById(Long seedApplyId)
    {
        return seedApplyMapper.selectSeedApplyById(seedApplyId);
    }

    /**
     * 查询种子申请列表
     *
     * @param seedApply 种子申请
     * @return 种子申请
     */
    @Override
    public List<SeedApply> selectSeedApplyList(SeedApply seedApply)
    {
        return seedApplyMapper.selectSeedApplyList(seedApply);
    }

    /**
     * 新增种子申请
     *
     * @param seedApply 种子申请
     * @return 结果
     */
    @Override
    public int insertSeedApply(SeedApply seedApply)
    {
        Long orderAllocationId = seedApply.getOrderAllocationId();
        OrderAllocation orderAllocation = orderAllocationMapper.selectOrderAllocationById(orderAllocationId);
        seedApply.setOrderId(orderAllocation.getOrderId());
        return seedApplyMapper.insertSeedApply(seedApply);
    }

    /**
     * 修改种子申请
     *
     * @param seedApply 种子申请
     * @return 结果
     */
    @Override
    public int updateSeedApply(SeedApply seedApply)
    {
        seedApply.setUpdateTime(DateUtils.getNowDate());
        return seedApplyMapper.updateSeedApply(seedApply);
    }

    /**
     * 批量删除种子申请
     *
     * @param seedApplyIds 需要删除的种子申请ID
     * @return 结果
     */
    @Override
    public int deleteSeedApplyByIds(Long[] seedApplyIds)
    {
        return seedApplyMapper.deleteSeedApplyByIds(seedApplyIds);
    }

    /**
     * 删除种子申请信息
     *
     * @param seedApplyId 种子申请ID
     * @return 结果
     */
    @Override
    public int deleteSeedApplyById(Long seedApplyId)
    {
        return seedApplyMapper.deleteSeedApplyById(seedApplyId);
    }
}
